package com.lsy.weizhi2.mybase;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.myutils.TitleViewCall;

/**
 * Created by 嗨哟 on 2017/3/23.
 */
public class MyTitleView2 extends RelativeLayout{
    private Context context;
    private ImageButton ib_back,search_ib;
    private TextView buy_tv;
    private TextView search_et;
    private TitleViewCall titleViewCall;
    public MyTitleView2(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        LayoutInflater.from(context).inflate(R.layout.my_title_view2,this,true);
        TypedArray typedArray=context.obtainStyledAttributes(attrs,R.styleable.MyTitleView);
        typedArray.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ib_back= (ImageButton) findViewById(R.id.ib_back);
        search_ib= (ImageButton) findViewById(R.id.search_ib);
        buy_tv= (TextView) findViewById(R.id.buy_tv);
        search_et= (TextView) findViewById(R.id.search_et);
        ib_back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                ((Activity)context).finish();
            }
        });
        search_et.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                titleViewCall.Click(view,TitleViewCall.SEARCH);
            }
        });
        buy_tv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                String text=buy_tv.getText().toString();
                titleViewCall.Click(view,TitleViewCall.TYPE);
            }
        });
        search_ib.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                titleViewCall.Click(v,TitleViewCall.CLOSE);
            }
        });
    }

    public void setTitleViewCall(TitleViewCall titleViewCall){
        this.titleViewCall=titleViewCall;
    }

    public String getText(){
        return search_et.getText().toString().trim();
    }

    public void setText(String str){
        search_et.setText(str);
    }

    public void setType(String str){
        buy_tv.setText(str);
    }

    public String getType(){
        return buy_tv.getText().toString();
    }

    public void setSearch_ib(int search){
        search_ib.setImageResource(search);
    }
}
